package utils.factory;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.SparseArray;

import fragment.CollectionPageFragment;
import fragment.FocusonPageFragment;
import fragment.HistoryPageFragment;

/**
 * Created by dllo on 15/11/17.
 */
public class CustomPageFragmentFactory {
    private static SparseArray<Fragment> fragmentMap = new SparseArray<>();

    public static Fragment createFragment(int position) {
        Fragment f = fragmentMap.get(position);
        if (f == null) {
            switch (position) {
                case 0:
                    f = new FocusonPageFragment();
                    break;
                case 1:
                    f = new CollectionPageFragment();
                    break;
                case 2:
                    f = new HistoryPageFragment();
                    break;
            }
            Bundle args = new Bundle();
            args.putInt("position", position);
            f.setArguments(args);
            fragmentMap.put(position, f);
        }
        return f;
    }
}